﻿using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using AvaloniaApplication1.Models;
using AvaloniaApplication1.ViewModels;
using ReactiveUI;

namespace AvaloniaApplication1.Views
{
    public class ShowTreeViewWindow : Window
    {
        private SignTreeModel _mSignTreeModel = new SignTreeModel();

        public ShowTreeViewWindow()
        {
            this.InitializeComponent();
#if DEBUG
            for (int i = 0; i < 1; i++)
            {
                SignTreeModel signTreeModel = new SignTreeModel();
                _mSignTreeModel.Children.Add(signTreeModel);
                for (int j = 0; j < 10; j++)
                {
                    SignTreeModel child = new SignTreeModel() { Name = j.ToString() };
                    signTreeModel.Children.Add(child);
                    for (int k = 0; k < 10; k++)
                    {
                        child.Children.Add(new SignTreeModel() { Name = $"{i}+{j}+{k}" });
                    }
                }
            }

            //treeView.DataContext = signTreeModel;
            ShowTreeVM showTreeVm= new ShowTreeVM();
            this.DataContext = _mSignTreeModel;
#endif
        }

        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);
        }

        private void AddDate_Click(object sender, RoutedEventArgs e)
        {
            SignTreeModel signTreeModel = new SignTreeModel();
            _mSignTreeModel.Children.Add(signTreeModel); 
            Random random=new Random();
            if (random.Next(0,2)==1)
            {
                signTreeModel.Children.Add(new SignTreeModel(){Name = random .NextDouble().ToString(),Icon=SignIcon.Error});
            }
        }
    }

    public class ShowTreeVM:ViewModelBase
    {
        private SignTreeModel _mSignTreeModel = new SignTreeModel();

        public SignTreeModel SignTreeModel1
        {
            get { return _mSignTreeModel; }
            set
            {
                _mSignTreeModel = value;
                this.RaiseAndSetIfChanged(ref _mSignTreeModel, value);
            }
        }

        private SignTreeModel _mSignTreeMode2 = new SignTreeModel();

        public SignTreeModel SignTreeModel2
        {
            get { return _mSignTreeMode2; }
            set
            {
                _mSignTreeMode2 = value;
                this.RaiseAndSetIfChanged(ref _mSignTreeMode2, value);
            }
        }

        public ShowTreeVM()
        {
            for (int i = 0; i < 1; i++)
            {
                SignTreeModel signTreeModel = new SignTreeModel();
                _mSignTreeModel.Children.Add(signTreeModel);
                for (int j = 0; j < 10; j++)
                {
                    SignTreeModel child = new SignTreeModel() { Name = j.ToString() };
                    signTreeModel.Children.Add(child);
                    for (int k = 0; k < 10; k++)
                    {
                        child.Children.Add(new SignTreeModel() { Name = $"{i}+{j}+{k}" });
                    }
                }
            }

            for (int i = 0; i < 1; i++)
            {
                SignTreeModel signTreeModel = new SignTreeModel();
                _mSignTreeMode2.Children.Add(signTreeModel);
                for (int j = 0; j < 10; j++)
                {
                    SignTreeModel child = new SignTreeModel() { Name = j.ToString() };
                    signTreeModel.Children.Add(child);
                    for (int k = 0; k < 10; k++)
                    {
                        child.Children.Add(new SignTreeModel() { Name = $"{i}+{j}+{k}" });
                    }
                }
            }
        }
    }
}
